<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>生物特征识别中心</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <meta http-equiv="Content-Language" content="zh-CN"/>
    <link rel="stylesheet" href="__CSS__/bootstrap.css">
    <link rel="stylesheet" href="__CSS__/my.css">
    <style>
        .th-1{
            width:20%;
        }
        .th-2,.th-3{
            width:40%;
        }
    </style>
</head>
<body>
{$nav}
<div class="container" id="container">
    <!-- ===============标题=================== -->
    <div>
        <div class="row">
            <div class="col-md-10 col-xs-9">
                <span class="heading"> 送样单位管理 </span>
            </div>
            <div class="col-md-2 col-xs-3">
                <button type="button" class="btn-lg btn-link btn-header" data-toggle="modal" data-target="#modal-unit-add"><span class="glyphicon glyphicon-plus" style="font-size: 16px"></span>&nbsp;新增单位
                </button>
            </div>
        </div>
    </div>
    <table class="table table-hover" id="table-unit" hidden="true">
        <thead>
        <tr>
            <th class="th-1">#</th>
            <th class="th-2">单位名称</th>
            <th class="th-3">操作</th>
        </tr>
        </thead>
        <tbody id="tbody-unit">
        </tbody>
    </table>

    <!-- ===============标题=================== -->
    <div>
        <div class="row">
            <div class="col-md-10 col-xs-9">
                <span class="heading"> 样品类型管理 </span>
            </div>
            <div class="col-md-2 col-xs-3">
                <button type="button" class="btn-lg btn-link btn-header" data-toggle="modal" data-target="#modal-sampletype-add"> <span class="glyphicon glyphicon-plus" style="font-size: 16px"></span>&nbsp;新增类型
                </button>
            </div>
        </div>
    </div>
    <table class="table table-hover" id="table-sampletype" hidden="true">
        <thead>
        <tr>
            <th class="th-1">#</th>
            <th class="th-2">类型名称</th>
            <th class="th-3">操作</th>
        </tr>
        </thead>
        <tbody id="tbody-sampletype">
        </tbody>
    </table>


    <!--=================编辑(modal)====================-->
    <div class="modal fade" id="modal-unit-update" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div style="margin: 20px 20px;">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <div style="margin: 0px 40px 0 20px;">
                        <div class="modal-header">
                            <h4 class="modal-title">编辑</h4>
                        </div>
                        <form class="form-horizontal" id="form-unit-update">
                            <div style="height: 40px"></div>
                            <input type="text" id="update_unit_id" name="id" hidden="true">
                            <div class="form-group">
                                <label for="update_unit_name" class="col-sm-3 control-label">名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="update_unit_name" name="name">
                                </div>
                            </div>
                            <div id="unit-update-result" style="margin-bottom: 0" hidden="true"></div>
                            <div style="height: 20px"></div>
                        </form>

                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp;取消</button>
                            <button type="button" class="btn btn-primary" id="unit-update-submit"><span class="glyphicon glyphicon-ok"></span>&nbsp;&nbsp;提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--=================编辑(modal)====================-->
    <div class="modal fade" id="modal-sampletype-update" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div style="margin: 20px 20px;">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <div style="margin: 0px 40px 0 20px;">
                        <div class="modal-header">
                            <h4 class="modal-title">编辑</h4>
                        </div>
                        <form class="form-horizontal" id="form-type-update">
                            <div style="height: 40px"></div>
                            <input type="text" id="update_sampletype_id" name="id" hidden="true">
                            <div class="form-group">
                                <label for="update_sampletype_name" class="col-sm-3 control-label">名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="update_sampletype_name" name="name">
                                </div>
                            </div>
                            <div id="type-update-result" hidden="true"></div>
                            <div style="height: 20px"></div>
                        </form>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp;取消</button>
                            <button type="button" class="btn btn-primary" id="sampletype-update-submit"><span class="glyphicon glyphicon-ok"></span>&nbsp;&nbsp;提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--=================新增(modal)====================-->
    <div class="modal fade" id="modal-unit-add" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div style="margin: 20px 20px;">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <div style="margin: 0px 40px 0 20px;">
                        <div class="modal-header">
                            <h4 class="modal-title">新增</h4>
                        </div>
                        <form class="form-horizontal" id="form-unit-add">
                            <div style="height: 40px"></div>
                            <div class="form-group">
                                <label for="add_unit_name" class="col-sm-3 control-label">名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="add_unit_name" name="name" placeholder="单位名称">
                                </div>
                            </div>
                            <div id="unit-add-result" hidden="true"></div>
                            <div style="height: 20px"></div>
                        </form>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp;取消</button>
                            <button type="button" class="btn btn-primary" id="unit-add-submit"><span class="glyphicon glyphicon-ok"></span>&nbsp;&nbsp;提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--=================新增(modal)====================-->
    <div class="modal fade" id="modal-sampletype-add" tabindex="-1" >
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div style="margin: 20px 20px;">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <div style="margin: 0px 40px 0 20px;">
                        <div class="modal-header">
                            <h4 class="modal-title">新增</h4>
                        </div>
                        <form class="form-horizontal" id="form-sampletype-add">
                            <div style="height: 40px"></div>
                            <div class="form-group">
                                <label for="add_sampletype_name" class="col-sm-3 control-label">名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="add_sampletype_name" name="name" placeholder="类型名称">
                                </div>
                            </div>
                            <div id="type-add-result" hidden="true"></div>
                            <div style="height: 20px"></div>
                        </form>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp;取消</button>
                            <button type="button" class="btn btn-primary" id="sampletype-add-submit"><span class="glyphicon glyphicon-ok"></span>&nbsp;&nbsp;提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>



    <!--===================删除确认框====================-->
    <div class="modal fade" id="delcfmModel">
        <div class="modal-dialog" style="width: 400px">
            <div class="modal-content">
                <div style="padding: 20px 20px;">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">×</span></button>
                    <h4 class="modal-title">提示信息</h4>
                </div>
                <div class="modal-body" align="center">
                    <p>确认删除？不可恢复哦</p>
                </div>
                <input type="hidden" id="del_url">
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" onclick="urlSubmit()">确定</button>
                </div>
            </div>
        </div>
    </div>
</div>

</div>
</body>
<script src="__JS__/jquery-3.2.1.min.js"></script>
<script src="__JS__/jquery.cookie.js"></script>
<script src="__JS__/bootstrap.min.js"></script>
<script src="__JS__/my.js"></script>
<script type="text/javascript">
    displayData("Unit");
    displayData("SampleType");

    /*===================显示数据===================*/
    function displayData(part) {
        var element=$("#tbody-"+part.toLowerCase());
        var table=$("#table-"+part.toLowerCase());
        var block = $(element);
        block.empty();
        $.post("/sample_rsv/" + part + "/getAll",null,function (data) {
            //遍历输出
            var datalenth = 0;
            for (var a in data) {
                var num = ++datalenth;
                var tr =
                    "<tr>" +
                    "<td>" + num + "</td>" +
                    "<td>" + data[a].name + "</td>" +
                    "<td>" +
                    "<a class='btn btn-md btn-link' onclick='update(\"" + part + "\"," + data[a].id + ");'>" +
                    "<span class='glyphicon glyphicon-edit'></span>&nbsp;" +
                    "</a>" +
                    "<a  class='btn btn-md btn-link' onclick='delcfm(\"/sample_rsv/" + part + "/del/id/" + data[a].id + "\",)'>" +
                    "<span class='glyphicon glyphicon-trash'></span>&nbsp;" +
                    "</a>" +
                    "</td>" +
                    "</tr>";
                block.append(tr);
            }
            //无数据时输出
            if (datalenth === 0) {
                var test_nodata = "<tr><h3><small>===============没有数据==============</small></h3></tr>";
                block.append(test_nodata);
            }else{
                table.fadeIn(200);
            }
        })

    }

    /*========================编辑===========================*/
    function update(title, id) {
        $.post('/sample_rsv/' + title + '/getById',{"id":id},function (data) {
            var arr_data = data;
            for (index in arr_data) {
                var element = $("#update_" + title.toLowerCase() + "_" + index);
                if (element.length > 0) element.val(arr_data[index]);
            }
            $("#modal-" + title.toLowerCase() + "-update").modal('show');
        });
    }

    $("#unit-update-submit").click(function () {
        $.post('/sample_rsv/Unit/edit',{data:$("#form-unit-update").toJson()},function (data) {
            $("#unit-update-result").showAjaxResult(data, '成功更新', '条记录');
        })
    });

    $("#sampletype-update-submit").click(function () {
        $.post('/sample_rsv/SampleType/edit',{data:$("#form-type-update").toJson()},function (data) {
            $("#type-update-result").showAjaxResult(data, '成功更新', '条记录');
        });
    });


    /*======================新增======================*/
    $("#unit-add-submit").click(function () {
        $.post('/sample_rsv/Unit/add',{data:$("#form-unit-add").toJson()},function (data) {
            $("#unit-add-result").showAjaxResult(data);
        });
    });
    $("#type-add-result").click(function () {
        $.post('/sample_rsv/SampleType/add',{data:$("#form-sampletype-add").toJson()}.serialize(),function (data) {
            $("#type-add-result").showAjaxResult(data);
        });
    });
    /*======================删除======================*/
    function delcfm(url) {
        $('#del_url').val(url);//给会话中的隐藏属性URL赋值
        $('#delcfmModel').modal();
    }

    function urlSubmit() {
        var del_url = $.trim($("#del_url").val());//获取会话中的隐藏属性URL
        $.post(del_url,null,function (data) {
            location.reload();
        });
    }

</script>
</html>
